﻿using System;
using System.Linq;
using System.Web.Mvc;
using System.ComponentModel.DataAnnotations;

using SimpleForum.Utils;
using SimpleForum.Data.Services;

namespace SimpleForum.Data.Models
{
    public partial class User
    {
        public int TotalReputation
        {
            get
            {
                return this.Reputation.Sum(x => x.ReputationEarned);
            }
        }

        public string AvatarUrl
        {
            get
            {
                string AvatarUrl;

                if (this.AvatarFilename == null) AvatarUrl = "http://www.gravatar.com/avatar/" + this.Email.Trim().ToLower().MD5Hash() + ".jpg?default=mm";
                else AvatarUrl = System.IO.Path.Combine(ConfigurationService.Get<string>("AvatarRelativePath"), this.AvatarFilename);

                return AvatarUrl;
            }
        }

        public string AvatarUrl32
        {
            get
            {
                return AvatarUrl + "&size=32";
            }
        }

        public string AvatarUrl128
        {
            get
            {
                return AvatarUrl + "&size=128";
            }
        }
    }
}